
package com.smart.common.constant;

import java.util.HashMap;
import java.util.Map;

public enum URLEnum {
    // 提交（心率，血压，血氧，体温，电量，呼吸，翻身次数，血糖，HRV，气压，海拔）数据
    SENSOR("sensor", 0),

    // 提交运动数据
    SUBMITSPORT("submitsport", 1),

    // 提交血糖数据
    SUBMITBLOODGLUCOSE("submitbloodglucose", 2),

    //提交睡眠数据（部分设备没此功能）
    SUBMITSLEEP("submitsleep", 3),

    //提交地理位置
    SUBMITLOCATION("submitlocation", 4),
    CHAT("chat", 5),
    POLICE("police",6);

    private final String url;
    private final int value;

    private static final Map<Integer, URLEnum> valueToEnumMap = new HashMap<>();
    private static final Map<String, URLEnum> urlToEnumMap = new HashMap<>();

    static {
        for (URLEnum constant : values()) {
            valueToEnumMap.put(constant.value, constant);
            urlToEnumMap.put(constant.url, constant);
        }
    }

    URLEnum(String url, int value) {
        this.url = url;
        this.value = value;
    }

    public String getUrl() {
        return url;
    }

    public int getValue() {
        return value;
    }

    public static URLEnum fromValue(int value) {
        return valueToEnumMap.get(value);
    }

    public static URLEnum fromUrl(String url) {
        return urlToEnumMap.get(url);
    }

    public static String getUrlFromValue(int value) {
        URLEnum constant = valueToEnumMap.get(value);
        return constant != null ? constant.getUrl() : null;
    }

    public static Integer getValueFromUrl(String url) {
        URLEnum constant = urlToEnumMap.get(url);
        return constant != null ? constant.getValue() : null;
    }
}